<?
require_once("IEndpointRetriever.php");
class UrlData
{
	public $Method;
	public $Url;
	public $QueryString;
	public $Cookie;
}
class UrlEndpointRetriever implements IEndpointRetriever
{
	protected $host;
	protected $extension;

	public function UrlEndpointRetriever($host, $extension)
	{
		$this->host = $host;
		$this->extension = $extension;
	}

	public function RetrieveEndpoint(Endpoint $endpoint)
	{
		$data = new UrlData();
		$data->Method = strtoupper($endpoint->GetMethod());
		if ($data->Method != 'GET' && $data->Method != 'POST')
			$data->Method = 'GET';
		$url = "http://$this->host/";
		$url .= implode($endpoint->GetParts(), "/");
		$url .= ".json";

		$data->Url = $url;

		$options = $endpoint->GetOptions();
		if ($options != null && count($options) > 0)
		{
			$data->QueryString = implode("&", 
				array_map(array($this, 'CreateOptionString'), $options));
		}
		$cookies = $endpoint->GetCookies();
		if ($cookies != null && count($cookies) > 0)
		{
			$data->Cookie = implode("&",
				array_map(array($this, 'CreateOptionString'), $cookies));
		}
		return $data;
	}
	protected function CreateOptionString(EndpointOption $endpointOption)
	{
		return $endpointOption->GetName() . "=" . $endpointOption->GetValue();
	}
}
?>
